define([],function (){
    const MuAvatarUploads = {
        template: `<div class="flex-row">
<el-upload
    v-model:file-list="fileList"
    list-type="picture"
    :action="uploadurl"
    :on-success="success"
    :on-remove="handleRemove"
  >
   
    <el-icon class="avatar-uploader-icon" size="20"><Plus /></el-icon>
  </el-upload><el-button type="primary" v-if="hasXz" size="small" style="margin-left: 10px" @click.stop="xzImg">选择图片</el-button>
</div>`,
        data(){
            return {
                fileList:[],
                uploadurl:''
            }
        },
        props:{
            modelValue:{
                type:Object,
                default:[]
            },
            hasXz:{
                type:Boolean,
                default:true
            }
        },
        emits:['update:modelValue'],
        watch:{
            modelValue(val){
                console.log(this.modelValue,'modelValue')
                console.log(this.fileList,'fileList')
                console.log(val,'vvvvvvvvvvvvvvvvvvvvv')
            }
        },
        created(){
            // console.log(Config,'cccccccccccccccc')
            this.uploadurl = `/app/muadmin/admin/ajax/upload`
        },
        mounted(){
            let fileList = [];
            if(this.modelValue){
                this.modelValue.forEach(item=>{
                    fileList.push({url:item})
                })
            }
            this.fileList = fileList
            // console.log(this.modelValue,'modelValue')
            // console.log(this.fileList,'fileList')
        },
        methods: {
            handUploadFiles(uploadFiles){
                let list = [];
                uploadFiles.forEach(item=>{
                    if(item?.response?.code == 1){
                        list.push(item.response.data.url)
                    }else{
                        list.push(item.url)
                    }
                })
                this.$emit('update:modelValue',list)
            },
            handleRemove(uploadFile, uploadFiles){
                this.handUploadFiles(uploadFiles)
            },
            success(response, uploadFile, uploadFiles){
                // console.log(response,  uploadFile, uploadFiles)
                this.handUploadFiles(uploadFiles);
            },
            xzImg(){
                let url = `/app/muadmin/admin/general/attachment/index?select=1&type=image/*&multiple=0`
                let that = this;
                window.callback = (data)=>{
                    that.fileList.push({url:data})
                    that.handUploadFiles(that.fileList)
                    // this.imageUrl = data;
                    // this.$emit('update:modelValue',data)
                    // console.log(data,'data')
                }
                layer.open({
                    type: 2,
                    title: '选择图片',
                    area: ['100%', '100%'],
                    content: url,
                    end:function (){
                        console.log('完成')
                    }
                })
            }
        }
    }
    return MuAvatarUploads
})